#ifndef _DVB_GROUP_DB_H
#define _DVB_GROUP_DB_H

#define SERVICETYPE_VIDEO					1	
#define SERVICETYPE_AUDIO					2
#define SERVICETYPE_TELETEXT				3
#define SERVICETYPE_NVODREF				4
#define SERVICETYPE_NVODSHIFT				5
#define SERVICETYPE_MOSAIC					6	
#define SERVICETYPE_FMRADIO				0xA	 
#define SERVICETYPE_DATA					0x0C
#define SERVICETYPE_MHP					0x10
#define SERVICETYPE_MPEG2_HDTV			0x11
#define SERVICETYPE_VIDEO_3D				0x1C
#define SERVICETYPE_ANALOG					0x20
#define SERVICETYPE_ADVANCE_SDTV			0x16
#define SERVICETYPE_ADVANCE_HDTV			0x19			


#define GROUP_SYS_PREFIX 			0x80000000	
#define GROUP_BOUQUET_PREFIX  	0x40000000		
#define GROUP_FAV_PREFIX  			0x20000000		
#define GROUP_VIDEO				(GROUP_SYS_PREFIX|SERVICETYPE_VIDEO)
#define GROUP_AUDIO				(GROUP_SYS_PREFIX|SERVICETYPE_AUDIO)
#define GROUP_NVOD					(GROUP_SYS_PREFIX|SERVICETYPE_NVODREF)
#define GROUP_TELETEXT 	 		(GROUP_SYS_PREFIX|SERVICETYPE_TELETEXT)
#define GROUP_DATA					(GROUP_SYS_PREFIX|SERVICETYPE_DATA)

typedef struct tagSERVICEGROUP
{
	struct tagSERVICEGROUP  *next;
	int						serviceCount;
	int						Capacity;	
	int						FavId;		
	char  					name[16];	
	unsigned short 			Curno;		
	dvb_service_t*			Services;		
}dvb_group_t;


extern int DVBGroupCreateDefaultGroup(int clearIfExist);

extern void DVBGroupsClear();

extern dvb_group_t* DVBGroupCreate(char *name,int favID);

extern int DVBGroupAdd(dvb_group_t* pGroup);

extern int DVBGroupDel(dvb_group_t* pGroup);

extern int  DVBGroupAddItem(dvb_group_t* pGroup,dvb_service_t* SerHandle);

extern int DVBGroupDelItem(dvb_group_t* pGroup,dvb_service_t* SerHandle);

extern void DVBGroupDelAllItem(dvb_group_t* pGroup);

extern dvb_group_t* DVBGroupGetByName(char *name);

extern dvb_group_t* DVBGroupGetByID(int FavId);

extern dvb_group_t* DVBSetCurGroup(dvb_group_t* pGroup);

extern dvb_group_t* DVBGetCurGroup();

extern dvb_group_t* DVBGroupGetBySerHandle(dvb_service_t* ServiceHandle);

extern int DVBGroupFindItem(dvb_group_t* pGroup,dvb_service_t* SerHandle);

extern int DVBGroupFindItemByTsidAndServiceid(dvb_group_t* pGroup, unsigned short network_id, unsigned short ts_id, unsigned short service_id);

extern dvb_service_t* DVBGroupFindItemByIndex(dvb_group_t* pGroup,int index);

extern int DVBGroupNetworkSort(dvb_group_t* pGroup, dvb_service_t* pstServiceList, unsigned int u32Cnt);

extern int DVBGroupDelService(dvb_service_t* handle);

extern int DVBGroupExchangeItemEx(dvb_group_t* pGroup,int idx1,int idx2);

#endif
